package com.springapi.service.impl;

import com.springapi.entity.Rolesdetail;
import com.springapi.dao.RolesdetailDao;
import com.springapi.service.RolesdetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (Rolesdetail)表服务实现类
 *
 * @author makejava
 * @since 2024-12-04 14:38:43
 */
@Service("rolesdetailService")
public class RolesdetailServiceImpl implements RolesdetailService {
    @Resource
    private RolesdetailDao rolesdetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Rolesdetail queryById(Integer id) {
        return this.rolesdetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param rolesdetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<Rolesdetail> queryByPage(Rolesdetail rolesdetail, PageRequest pageRequest) {
        long total = this.rolesdetailDao.count(rolesdetail);
        return new PageImpl<>(this.rolesdetailDao.queryAllByLimit(rolesdetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param rolesdetail 实例对象
     * @return 实例对象
     */
    @Override
    public Rolesdetail insert(Rolesdetail rolesdetail) {
        this.rolesdetailDao.insert(rolesdetail);
        return rolesdetail;
    }

    /**
     * 修改数据
     *
     * @param rolesdetail 实例对象
     * @return 实例对象
     */
    @Override
    public Rolesdetail update(Rolesdetail rolesdetail) {
        this.rolesdetailDao.update(rolesdetail);
        return this.queryById(rolesdetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.rolesdetailDao.deleteById(id) > 0;
    }
}
